package com.marc.eden;


import android.support.v7.app.AppCompatActivity;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Bundle;
import android.view.TextureView;

import com.marc.eden.util.MyCamera;
import com.megvii.facepp.sdk.Facepp;

public class ScannerActivity extends AppCompatActivity {

    private boolean is106Points;
    private int min_face_size;
    private int detection_interval;
    private Facepp myFacepp;
    private HandlerThread myHandlerThread = new HandlerThread("myFacepp");
    private Handler myHandler;
    private TextureView myTextureView;
    private MyCamera myCamera;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scanner);
        init();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                myCamera.openMyCamera(myHandler, myTextureView);
            }
        }, 2000);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (myCamera != null) {
            Facepp.FaceppConfig faceppConfig = myFacepp.getFaceppConfig();
            faceppConfig.interval = detection_interval;
            faceppConfig.minFaceSize = min_face_size;
        }
    }

    private void init() {
        is106Points = getIntent().getBooleanExtra("is106Points", false);
        min_face_size = getIntent().getIntExtra("min_face_size", 33);
        detection_interval = getIntent().getIntExtra("detection_interval",1);
        myFacepp = new Facepp();
        myHandlerThread.start();
        myHandler = new Handler(myHandlerThread.getLooper());
        myTextureView = (TextureView) findViewById(R.id.textureView);
        myCamera = new MyCamera();

    }
}
